package org.example.ecommerce_system.mapper;

import org.apache.ibatis.annotations.*;
import org.example.ecommerce_system.entity.Product;

import java.util.List;

@Mapper
public interface ProductMapper {


    @Select("select * from product ")
    List<Product> getAll();

    @Select("select * from product where proName like concat('%',#{proName},'%')")
    List<Product> searchProduct(String proName);

    @Select("select proPrice from product where TRIM(proName)=TRIM(#{proName})")
    Double getPrice(String proName);

    @Select("select * from product where proID=#{proID}")
    Product getProductByID(int proID);

    @Select("select * from product where proName=#{proName}")
    Product getProductByName(String proName);

    @Delete("delete from product where proID=#{proID}")
    int deleteProduct(int proID);

    @Insert("insert into product values (null,#{proName},#{proDetail},#{proPrice},#{quantity},#{imgPath})")
    int insertProduct(Product product);

    @Update("update product set proName=#{proName},proDetail=#{proDetail},proPrice=#{proPrice},quantity=#{quantity},imgPath=#{imgPath} where proID=#{proID}")
    int updateProduct(Product product);

    @Update("update product set quantity=#{quantity} where proName=#{proName}")
    int updateQuantity(@Param("proName") String proName,
                       @Param("quantity") Integer quantity);
}

